/ leetcodesolve / Reverse Integer.py
swadhinbiswas update · 4/20/2024
2cf2dbd
13 lines · 275 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
class Solution:
    def reverse(self, x: int) -> int:
      while True:
        if x<0:
          x = int(str(x)[1:][::-1]) * -1
        else:
          x = int(str(x)[::-1])
        if x < -2**31 or x > 2**31-1:
          return 0
        return x
      

print(-2147483648)